
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <link href="../../style/css/style.css" rel="stylesheet" type="text/css" />
    <script src="../../style/js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript">
        $(function () {
            var  id =(location.search).split("=")[1];
            $("input[name='id']").val(id);
            //查询所有角色
            $.get("../../admin/roles",function (res){
                //查询管理员
                $.get("../../admin/findAdmin",{id:id},function(data){
                    var str="";
                    //循环生成所有角色
                    for (var i = 0; i < res.data.length; i++) {
                        str+="<input type='checkbox' value='"+res.data[i].id+"' name='roleId'";
                        for (var j = 0; j < data.data.roleList.length; j++) {
                            if (res.data[i].id == data.data.roleList[j].id){
                                str+="checked";
                            }
                        }
                        str+="/>"+res.data[i].name;
                    }
                    $("input[name='account']").val(data.data.account);
                    console.log(data.data.account)
                    $("#rolesId").html(str);//生成角色复选框
                })
            },"json");
        })
/*        //修改保存
        function subform() {
            var  id =(location.search).split("=")[1];
            var account =$("#account").val();
            // var rolesId =$("#rolesId").val();
            $.post("../../admin/update",{account:account,rolesId:rolesId,id:id},function (res) {
                if (res.code==200){
                    alert("修改成功!!");
                    location.assign("list.html");
                }else {
                    alert("服器忙碌");
                }
            });
        }*/


        function subform() {
            $.post("../../admin/save",$("#formId").serialize(), function (res) {
                if (res.code == 201) {
                    alert("服务器忙！");
                    window.parent.location.replace("../login.html");
                } else if (res.code == 500) {
                    alert("修改失败");
                } else {
                    alert("修改成功");
                    location.replace("list.html");
                }
            });
        }
    </script>
</head>
<body>
<form id="formId">
    <div class="formbody">
        <div class="formtitle"><span>基本信息</span></div>
        <ul class="forminfo">
            <input type="hidden" name="id" id="id">
            <li>
                <label>账号</label>
                <input name="account" id="account"  type="text" class="dfinput" />
            </li>
            <li>
                <label>角色</label>
                <span id="rolesId"></span>
            </li>

            <li>
                <input name="" type="button" class="btn" value="确认修改" onclick="subform()"/>
            </li>
        </ul>
    </div>
</form>

</body>
</html>